package com.example.utils;

import com.example.pojo.entity.Account;

/**
 * 账户工具类
 */
public class AccountUtils {

    // 使用 threadLocal 存放当前账户
    private static final ThreadLocal<Account> threadLocal = new ThreadLocal<>();


    /**
     * 获取当前登录的账户
     *
     * @return  当前登录的账户
     */
    public static Account getCurrentLoginAccount() {
        return threadLocal.get();
    }

    /**
     * 存放当前登录的账户
     *
     * @param account 当前登录的账户
     */
    public static void setCurrentLoginAccount(Account account) {
        threadLocal.set(account);
    }

    /**
     * 清除 threadLocal
     */
    public static void remove() {
        threadLocal.remove();
    }
}
